package es.jclm.agri.foragri.controller;

import java.io.IOException;
import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.support.RequestContextUtils;

@Controller
public class HelloWorldController {
 
    @RequestMapping("/helloworld.html")
    public String sayHello(){
        System.out.println("Hello World from Controller 1");
        
        return "views/welcome";
    }
    
    @RequestMapping("/hola.html")
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
 
        try {
            RequestContextUtils.getLocaleResolver(request).setLocale(request, response, new Locale(request.getParameter("language")));
        } catch (Exception ex) {
        	System.out.println(ex.getMessage());
        }
        
        System.out.println("Hello World from Controller 1");
        System.out.println("language=" + request.getParameter("language"));
        return new ModelAndView("views/welcome");
    }
 
}
